package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.StudentBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IStudentMapper extends BaseMapper<StudentBean> {


    @Select("SELECT s.*,c.c_name FROM t_room  r JOIN t_student s ON pk_roomId=fk_roomId JOIN t_class c ON pk_classId=fk_classId WHERE pk_roomId=#{roomId}")
    @ResultMap("stuMap")
    public List<StudentBean> findStudentByRoomId(Integer roomId);


    public IPage<StudentBean> findByItem(Page page,
                                         @Param("studentName") String studentName,
                                         @Param("className") String className,
                                         @Param("room") String roomAddress);

    @Select("SELECT s.*,c.c_name,r.`r_address`,pk_roomId FROM t_room  r JOIN t_student s ON pk_roomId=fk_roomId" +
            " JOIN t_class c ON pk_classId=fk_classId WHERE pk_studentId=#{studentId}")
    @ResultMap("stuMap")
    public StudentBean findById(Integer studentId);

}
